package health.lm.com.find.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.androidkun.xtablayout.XTabLayout;
import com.lm.sjy.titlebar.widget.CommonTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import health.lm.com.component_base.base.adapter.BaseFragmentAdapter;
import health.lm.com.component_base.base.mvp.fragment.XFragment;
import health.lm.com.find.R;
import health.lm.com.find.R2;
import health.lm.com.router.ARouterConstant;

/**
 * @author GQI
 * @description: 链活动
 * @date :2019-08-14 9:00
 */
@Route(path = ARouterConstant.ActivityFragment)
public class ActivityFragment extends XFragment {
    @BindView(R2.id.title_bar)
    CommonTitleBar titlebar;
    @BindView(R2.id.xTablayout)
    XTabLayout xTablayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;
    List<Fragment> fragments = new ArrayList<>();
    private String id[] = {"1","2"};
    @Override
    public int getLayoutId() {
        return R.layout.fragment_activity;
    }

    @Override
    public Object newP() {
        return null;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        initViewPager();
    }
    private void initViewPager() {
        List<String> titles = new ArrayList<>();
        titles.add("链活动");
        titles.add("会员联盟商");
        fragments.add( HActivityFragment.getInstance(id[0]));
        fragments.add( MemberAffiliateFragment.getInstance(id[1]));
        BaseFragmentAdapter adatper = new BaseFragmentAdapter(getChildFragmentManager(), fragments, titles);
        viewPager.setAdapter(adatper);
        viewPager.setOffscreenPageLimit(2);
        //将TabLayout和ViewPager关联起来。
        xTablayout.setupWithViewPager(viewPager);
        //给TabLayout设置适配器
        xTablayout.setupWithViewPager(viewPager);

    }
}
